//
//@File    :	14.4_studenti.h
//@Time    :	2022/01/20 11:09:43
//@Auther  :	Sun Sheng
//@Contact :	970340843@qq.com
//@Desc    :	defining a Student class using private inheritance
//
#ifndef STUDENTI_H_
#define STUDENTI_H_

#include <iostream>
#include <valarray>
#include <string>

class Student : private std::string, private std::valarray<double>
{
private:
    typedef std::valarray<double> ArrayDb;
    //private method for scores output
    std::ostream &arr_out(std::ostream &os) const;

public:
    Student() : std::string("Null Student"), ArrayDb() {}
    //对于只有一个参数的构造函数,使用explicit防止隐式转换
    explicit Student(const std::string &s) : std::string(s), ArrayDb() {}
    explicit Student(int n) : std::string("Nully"), ArrayDb(n) {}
    Student(const std::string &s, int n) : std::string(s), ArrayDb(n) {}
    Student(const std::string &s, const ArrayDb &a) : std::string(s), ArrayDb(a) {}
    Student(const char *str, const double *pd, int n) : std::string(str), ArrayDb(pd, n) {}
    ~Student() {}
    double Average() const;
    double &operator[](int i);
    double operator[](int i) const;
    const std::string &Name() const;
    //friends
    //input
    friend std::istream &operator>>(std::istream &is, Student &stu); //1 word
    friend std::istream &getline(std::istream &is, Student &stu);    //1 line
    //output
    friend std::ostream &operator<<(std::ostream &os, const Student &stu);
};

#endif // STUDENTI_H_
